package cn.iocoder.yudao.module.crossborder.finance.api;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.crossborder.finance.api.dto.ExchangeRateDTO;
import cn.iocoder.yudao.module.crossborder.finance.api.dto.SettlementDTO;
import cn.iocoder.yudao.module.crossborder.finance.service.FinanceService;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.validation.annotation.Validated;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.List;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

/**
 * 财务结算管理 API 接口实现类
 *
 * @author LHL
 */
@RestController // 提供 RESTful API 接口，给 Feign 调用
@Validated
public class FinanceApiImpl implements FinanceApi {

    @Resource
    private FinanceService financeService;

    @Override
    public CommonResult<SettlementDTO> getSettlement(Long id) {
        SettlementDTO settlement = financeService.getSettlement(id);
        return success(settlement);
    }

    @Override
    public CommonResult<List<SettlementDTO>> getSettlementList(List<Long> ids) {
        List<SettlementDTO> settlements = financeService.getSettlementList(ids);
        return success(settlements);
    }

    @Override
    public CommonResult<Long> createSettlement(SettlementDTO settlement) {
        Long id = financeService.createSettlement(settlement);
        return success(id);
    }

    @Override
    public CommonResult<ExchangeRateDTO> getExchangeRate(String fromCurrency, String toCurrency) {
        ExchangeRateDTO exchangeRate = financeService.getExchangeRate(fromCurrency, toCurrency);
        return success(exchangeRate);
    }

    @Override
    public CommonResult<BigDecimal> calculateFee(Long orderId, Integer feeType) {
        BigDecimal fee = financeService.calculateFee(orderId, feeType);
        return success(fee);
    }

    @Override
    public CommonResult<Boolean> processSettlement(Long orderId) {
        Boolean result = financeService.processSettlement(orderId);
        return success(result);
    }

}
